package com.yingsheng.bi.hks.repository.dao.service;

import com.yingsheng.bi.hks.dto.employee.ResumeQryReq;
import com.yingsheng.bi.hks.repository.dao.mapper.ResumeExtMapper;
import com.yingsheng.bi.hks.repository.dao.mapper.ResumeInfoMapper;
import com.yingsheng.bi.hks.repository.dao.po.ResumeInfo;
import com.yingsheng.bi.hks.repository.dao.po.ResumeInfoExample;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * resume_info表的数据库操作服务
 * 要求说明：
 * 1.一般情况下,要求参数不超过5个时方法入参逐个声明
 * 2.一般情况下,要求条件不超过3个时要在方法名上体现
 * 3.最好对方法入参做一定校验,尤其是对条件参数至少要做非空校验
 *
 * @author 83686
 */
@Repository
public class ResumeInfoDaoService {

    @Autowired
    private ResumeInfoMapper resumeInfoMapper;

    @Autowired
    private ResumeExtMapper resumeExtMapper;

    public boolean insert(ResumeInfo resumeInfo) {
        int result = resumeInfoMapper.insert(resumeInfo);
        return result == 1;
    }

    public List<String> selectResumeIdsByUserIdAndState(String userId, String state) {
        return resumeExtMapper.selectResumeIdsByUserIdAndState(userId, state);
    }

    public List<ResumeInfo> qryByIds(List<String> ids) {
        ResumeInfoExample example = new ResumeInfoExample();
        example.createCriteria().andIdIn(ids);
        return resumeInfoMapper.selectByExample(example);
    }

    public List<ResumeInfo> qryByReq(ResumeQryReq req) {
        ResumeInfoExample example = new ResumeInfoExample();
        ResumeInfoExample.Criteria criteria = example.createCriteria();
        if (!StringUtil.isNullOrEmpty(req.getWorkStatus())) {
            criteria.andWorkStatusEqualTo(req.getWorkStatus());
        }
        if (!StringUtil.isNullOrEmpty(req.getName())) {
            criteria.andNameEqualTo(req.getName());
        }
        if (!StringUtil.isNullOrEmpty(req.getIdCard())) {
            criteria.andEducationEqualTo(req.getEducation());
        }
        return resumeInfoMapper.selectByExample(example);
    }

    public ResumeInfo qryByUserId(String userId) {
        ResumeInfoExample example = new ResumeInfoExample();
        ResumeInfoExample.Criteria criteria = example.createCriteria();
        criteria.andUserIdEqualTo(userId);
        List<ResumeInfo> resumeInfos = resumeInfoMapper.selectByExample(example);
        if (resumeInfos.isEmpty()){
            return null;
        }
        return resumeInfos.get(0);
    }
}
